package ide.ccf.ccproject.editors;

import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.TextAttribute;
import org.eclipse.jface.text.presentation.IPresentationReconciler;
import org.eclipse.jface.text.presentation.PresentationReconciler;
import org.eclipse.jface.text.rules.DefaultDamagerRepairer;
import org.eclipse.jface.text.rules.Token;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.jface.text.source.SourceViewerConfiguration;

/**
 * CCF项目文件查看器配置类
 *
 */
public class ProjectFileViewerConfiguration extends SourceViewerConfiguration 
{
	private ProjectFileScanner scanner;
	private ColorManager colorManager;

	/**
	 * 构造器
	 * @param colorManager
	 */
	public ProjectFileViewerConfiguration(ColorManager colorManager) 
	{
		this.colorManager = colorManager;
	}

	/**
	 * 获取CCF工程文件扫描器
	 * @return
	 */
	protected ProjectFileScanner getProjectFileScanner() 
	{
		if (scanner == null) 
		{
			scanner = new ProjectFileScanner(colorManager);
			scanner.setDefaultReturnToken(new Token(new TextAttribute(colorManager.getColor(IProjectFileColorConstants.DEFAULT))));
		}
		return scanner;
	}

	/**
	 * 获取源码视图使用的CCF工程文件显示协调器
	 */
	public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) 
	{
		PresentationReconciler reconciler = new PresentationReconciler();
		DefaultDamagerRepairer dr;
		dr = new DefaultDamagerRepairer(getProjectFileScanner());
		
		reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
		reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
		
		return reconciler;
	}
}